<template>
    <div id="AdminArticleManger">
        <el-table :data="tableData" style="width: 100%">
            <el-table-column label="标题" prop="title"> </el-table-column>
            <el-table-column label="时间">
                <template #default="scope">
                    {{ formatDate(scope.row.publishTime) }}
                </template>
            </el-table-column>
            <el-table-column label="操作" width="300">
                <template #default="scope">
                    <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)"
                        >删除</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
export default {
    name: "AdminArticleManger",
    data() {
        return {
            tableData: [],
        };
    },
    methods: {
        // 处理时间
        formatDate(val) {
            let date = new Date(val),
                YY = date.getFullYear(),
                MM = date.getMonth() + 1,
                DD = date.getDate(),
                hh = date.getHours(),
                mm = date.getMinutes(),
                ss = date.getSeconds();

            hh < 10 && (hh = "0" + hh);
            mm < 10 && (mm = "0" + mm);
            ss < 10 && (ss = "0" + ss);

            return `${YY}-${MM}-${DD} ${hh}:${mm}:${ss}`;
        },
        handleDelete(index, row) {
            console.log("?");
            this.$axios({
                method: "get",
                headers: { token: localStorage.getItem("token") || "" },
                url: `http://localhost:8081/ts/admin/deleteArticle?articleId=${row.serial}`,
            }).then((res) => {
                this.$message.success("操作成功");
                this.initArticleInfo();
            });
        },

        initArticleInfo: function () {
            this.$axios({
                method: "get",
                headers: { token: localStorage.getItem("token") || "" },
                url: `http://localhost:8081/ts/admin/allArticleInfo?isNeedAds=1`,
            }).then((res) => {
                this.tableData = res.data.respData;
            });
        },
    },
    created() {
        this.initArticleInfo();
    },
};
</script>

<style lang="less" scoped></style>














